package com.yfw.maple_leaf_store.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfw.maple_leaf_store.common.R;
import com.yfw.maple_leaf_store.domain.Category;
import com.yfw.maple_leaf_store.domain.User;
import com.yfw.maple_leaf_store.service.CategoryService;
import com.yfw.maple_leaf_store.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.*;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author: yfw
 * @date: 2022/6/14 19:43
 * com.yfw.maple_leaf_store.controller
 */
@Controller
@ResponseBody //不用RestController
@Slf4j
@RequestMapping("/cate")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 添加分类
     * @param category
     * @return
     */
    @PostMapping("/addCateGory")
    public R<String> addCateGory(@RequestBody Category category){
        categoryService.save(category);
        return R.success("添加成功");
    }

    /**
     * 查询所有分类
     */
    @GetMapping("/list")
    public R<List<Category>> page(){
        //查询所有分类
        List<Category> list = categoryService.list();
        return R.success(list);
    }
}

